package com.ciaojian.store.controller;

import com.ciaojian.core.model.dto.SchedulingDTO;
import com.ciaojian.core.util.Result;
import com.ciaojian.store.service.SchedulingServiceImpl;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @author Atlakyn
 */
@RestController
@RequestMapping("/schedules")
public class SchedulingController {
    @Resource
    private SchedulingServiceImpl schedulingService;

    @ApiOperation(value = "日程详情(按单日)", response = SchedulingDTO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "发型师ID", name = "workerId"),
            @ApiImplicitParam(value = "日期", name = "day", paramType = "query")
    })
    @GetMapping("/detail-day")
    public Result getDetailByDay(@NotNull(message = "发型师ID不能为空") Integer workerId,
                                 @NotNull(message = "日期不能为空") @DateTimeFormat(pattern = "yyyy-MM-dd") Date day) {
        return Result.ok(schedulingService.getBaseMapper().findByWorkerAndDate(workerId, day));
    }


    @ApiOperation(value = "发型师排班日历", response = SchedulingDTO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "发型师ID", name = "workerId"),
            @ApiImplicitParam(value = "月份", name = "month", paramType = "query")
    })
    @GetMapping("/calendar")
    public Result calendar(@NotNull(message = "发型师ID不能为空") Integer workerId,
                           @NotNull(message = "日期不能为空") @DateTimeFormat(pattern = "yyyy-MM") Date month) {
        return Result.ok(schedulingService.getBaseMapper().findCalendarByWorker(workerId, month));
    }
}
